/*
	Lib Name : water mark text
	How to use : $(".input").waterMarkText();
			  	 $(".input").waterMarkText(opt);
				 *opt is array and style of span tag
*/
(function ($) {

    /*options for span tag*/
    var opt = {
        "color": "#A7A7A7",
        "position": "absolute",
        "padding": "0px 0px 0px 10px",
        "top": "3px",
        "left": "0px",
        "cursor": "text",
        "text-decoration": "none",
        "font-weight": "normal",
		"display":"block"
    };

    $.fn.waterMarkText = function (options) {
        $.extend(opt, options);
        $obj = $(this);

        init($obj);

        $obj.focus(function () {
            $(this).next("span.WaterMarkTextSpan").hide();
            $(this).css("color", "black");
        }).blur(function () {
            if ($(this).val().length < 1) $(this).next().show();
        });

        $obj.filter(function(){
			if($(this).val() != undefined && $(this).val() != "")
				return true;
			else if($(this).text() != ""){
				return true;
			}			
			return false;
		}).each(function () {
            $(this).next("span.WaterMarkTextSpan").hide();
        });
    }

    init = function (obj) {
        $obj.css("padding-left", "10px").each(function () {
            var obj = $(this);

            /*options for div tag*/
            var optDiv = {
                "margin-top": obj.css("margin-top"),
                "margin-right": obj.css("margin-right"),
                "margin-bottom": obj.css("margin-bottom"),
                "margin-left": obj.css("margin-left"),
                "position": "relative",
                "padding": "0px",
				"float":"left"
            };
            opt["font-size"] = obj.css("font-size");
            opt["font-family"] = obj.css("font-family");
            obj.css("margin", "0px")
				.wrap($("<div>").css(optDiv))
				.closest("div")
				.append($("<span class='WaterMarkTextSpan'>" + this.title + "</span>").css(opt)
				        .bind("click", function () {
				            $(this).hide();
				            obj.focus();
				        }));			
        });
        return obj;
    }

})(jQuery);